/*
 * @features: 功能
 * @description: 说明
 * @Date: 2021-09-30 23:49:57
 * @Author: judu233(769471424@qq.com)
 * @LastEditTime: 2021-10-03 13:28:56
 * @LastEditors: judu233
 */
import { Label } from "cc";
import { _decorator, error, EditBox } from "cc";
import { ProxyOb } from "./Core/ProxyOb";
import VmBase from "./Core/VmBase";

const { ccclass, property, menu } = _decorator;

@ccclass
@menu('VM/VM-EditBox')
export default class VmEditBox extends VmBase {
    /**代理对象 */
    proxy: ProxyOb<EditBox>['proxy'];

    onDataInit() {
        try {
            if (this.watch.controller) {
                this.node.on(EditBox.EventType.TEXT_CHANGED, this.editBoxChange, this);
                this.proxyOb.isCheckValue = false;
            }
            this.setComponentValue(ProxyOb.getValue(this.watch.path, '?'));
        } catch (err) {
            error(`节点：${this.node.name}组件的VmProgress组件init失败`);
            error(err);
        }
    }

    /**文本框改变改变 */
    editBoxChange(editor: EditBox) {
        this.proxy.string = editor.string;
    }
}
